package servlet.manage;

import data.Select;
import data.Updata;
import servlet.Control;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ChangeRootPwd",value = "/manage/changeRootPwd")
public class ChangeRootPwd extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pwd=request.getParameter("pwd");
        String oldPwd=request.getParameter("oldPwd");

        String count=Select.rootPwd(oldPwd);
        if(!count.equals(1+"")){
            Control.fail(response,"原密码不正确！");
            return;
        }

        Updata.changeRootMistake(pwd);
        Control.success(response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
